```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>线程池核心线程创建机制详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            color: #e2e8f0;
        }
        .hover-scale {
            transition: transform 0.3s ease;
        }
        .hover-scale:hover {
            transform: scale(1.02);
        }
        .highlight-box {
            border-left: 4px solid #6e8efb;
            transition: all 0.3s ease;
        }
        .highlight-box:hover {
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">线程池核心线程创建机制</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">深入解析Java线程池中核心线程的创建时机与工作机制</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">
                    <i class="fas fa-code mr-2"></i>Java并发编程
                </span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">
                    <i class="fas fa-cogs mr-2"></i>线程池原理
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg text-gray-700 leading-relaxed mb-8">
                线程池是Java并发编程中的核心组件之一，理解核心线程的创建时机对于编写高效的多线程程序至关重要。本文将详细解析线程池核心线程的创建机制，并通过代码示例和可视化图表帮助您深入理解这一重要概念。
            </p>
            <div class="flex items-center justify-center my-10">
                <div class="w-full md:w-4/5">
                    <div class="mermaid">
                        graph TD
                            A[线程池初始化] -->|创建| B[核心线程]
                            C[任务提交] -->|核心线程不足| B
                            B --> D[执行任务]
                            C -->|核心线程已满| E[任务队列]
                            E -->|队列已满| F[创建非核心线程]
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Thread Creation Timings -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 border-b pb-4">核心线程创建时机</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <!-- Card 1 -->
                <div class="bg-white p-6 rounded-xl shadow-md hover-scale highlight-box">
                    <div class="text-blue-500 text-3xl mb-4">
                        <i class="fas fa-play-circle"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">初始化线程池时</h3>
                    <p class="text-gray-600">
                        当你创建一个线程池(如使用<code>Executors.newFixedThreadPool()</code>或<code>ThreadPoolExecutor</code>)，核心线程会在池初始化时被创建。线程池会根据<code>corePoolSize</code>参数创建相应数量的核心线程。
                    </p>
                </div>
                
                <!-- Card 2 -->
                <div class="bg-white p-6 rounded-xl shadow-md hover-scale highlight-box">
                    <div class="text-blue-500 text-3xl mb-4">
                        <i class="fas fa-tasks"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">任务到达时</h3>
                    <p class="text-gray-600">
                        在<code>ThreadPoolExecutor</code>中，如果当前活跃线程数少于<code>corePoolSize</code>且有新任务提交，线程池会立即创建新核心线程处理任务。这确保了即使任务队列为空，核心线程仍能处理新任务。
                    </p>
                </div>
                
                <!-- Card 3 -->
                <div class="bg-white p-6 rounded-xl shadow-md hover-scale highlight-box">
                    <div class="text-blue-500 text-3xl mb-4">
                        <i class="fas fa-clock"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">线程池处于空闲状态时</h3>
                    <p class="text-gray-600">
                        如果线程池中的线程数小于核心线程数且没有待执行任务时，线程池不会主动创建新核心线程。核心线程只有在任务到达时才会被创建并开始执行。
                    </p>
                </div>
            </div>
        </section>

        <!-- Implementation Details -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 border-b pb-4">具体实现</h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10 hover-scale">
                <div class="p-5 bg-gray-800 flex items-center">
                    <div class="h-3 w-3 rounded-full bg-red-500 mr-2"></div>
                    <div class="h-3 w-3 rounded-full bg-yellow-500 mr-2"></div>
                    <div class="h-3 w-3 rounded-full bg-green-500 mr-2"></div>
                    <div class="text-gray-300 text-sm ml-2">ThreadPoolDemo.java</div>
                </div>
                <div class="code-block p-6 overflow-x-auto">
                    <pre><code class="language-java">import java.util.concurrent.*;

public class ThreadPoolDemo {
    public static void main(String[] args) {
        // 创建一个核心线程数为 5 的线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
            5,  // corePoolSize
            10, // maximumPoolSize
            60, // keepAliveTime
            TimeUnit.SECONDS,
            new LinkedBlockingQueue&lt;Runnable&gt;()
        );

        // 提交任务
        executor.submit(() -> System.out.println("Task executed"));
    }
}</code></pre>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-md hover-scale">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-info-circle text-blue-500 mr-2"></i>
                        空闲线程处理
                    </h3>
                    <p class="text-gray-600">
                        当线程池中的线程数超过核心线程数时，如果这些线程处于空闲状态，并且空闲时间超过<code>keepAliveTime</code>，它们可能会被回收。然而，核心线程不会被回收，即使在空闲状态下，它们也会保持活动状态，直到线程池被关闭。
                    </p>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-md hover-scale">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-project-diagram text-blue-500 mr-2"></i>
                        线程池工作原理
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-blue-500 text-xs mt-1 mr-2"></i>
                            <span><strong>任务提交</strong>：当任务提交到线程池时，线程池检查当前活跃线程数。如果少于<code>corePoolSize</code>，会创建新核心线程处理任务。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-blue-500 text-xs mt-1 mr-2"></i>
                            <span><strong>任务队列</strong>：如果所有核心线程都在忙碌且任务队列未满，任务会被添加到队列中。否则，创建新线程直到达到<code>maximumPoolSize</code>。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chevron-right text-blue-500 text-xs mt-1 mr-2"></i>
                            <span><strong>线程复用</strong>：核心线程会重复使用来执行任务，避免了线程频繁创建和销毁带来的性能开销。</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
        
        <!-- Visualization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 border-b pb-4">线程池工作流程可视化</h2>
            <div class="bg-white p-6 rounded-xl shadow-md hover-scale">
                <img src="https://cdn.nlark.com/yuque/0/2021/png/21449790/1637804411544-41a889b6-1476-455a-8b51-a405dbe729d4.png" 
                     alt="线程池工作流程图" 
                     class="w-full h-auto rounded-lg border border-gray-200">
                <p class="text-sm text-gray-500 mt-2 text-center">线程池工作流程图展示了任务从提交到执行的完整流程</p>
            </div>
        </section>
        
        <!-- Summary -->
        <section class="bg-blue-50 p-8 rounded-xl">
            <h2 class="text-2xl font-bold mb-4 text-gray-800 flex items-center">
                <i class="fas fa-lightbulb text-yellow-500 mr-2"></i>
                关键总结
            </h2>
            <div class="grid md:grid-cols-2 gap-4">
                <div class="flex items-start">
                    <div class="bg-blue-100 p-2 rounded-full mr-3">
                        <i class="fas fa-check text-blue-500"></i>
                    </div>
                    <p class="text-gray-700">核心线程在初始化时创建，或者当有新任务提交且当前线程数少于<code>corePoolSize</code>时创建</p>
                </div>
                <div class="flex items-start">
                    <div class="bg-blue-100 p-2 rounded-full mr-3">
                        <i class="fas fa-check text-blue-500"></i>
                    </div>
                    <p class="text-gray-700">核心线程不会被回收，即使处于空闲状态</p>
                </div>
                <div class="flex items-start">
                    <div class="bg-blue-100 p-2 rounded-full mr-3">
                        <i class="fas fa-check text-blue-500"></i>
                    </div>
                    <p class="text-gray-700">合理设置<code>corePoolSize</code>和<code>maximumPoolSize</code>对性能优化至关重要</p>
                </div>
                <div class="flex items-start">
                    <div class="bg-blue-100 p-2 rounded-full mr-3">
                        <i class="fas fa-check text-blue-500"></i>
                    </div>
                    <p class="text-gray-700">线程复用机制显著减少了线程创建和销毁的开销</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专业的技术知识分享平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" 
                       class="text-blue-400 hover:text-blue-300 transition duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        访问技术小馆
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Add smooth scrolling
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```